#include "widget.h"
#include "ui_widget.h"

#include<QPainter>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::paintEvent(QPaintEvent *event)
{
    (void) event;
    //绘图工作放到这里来执行

    QPainter painter(this);

    QPen pen;
    //设置颜色
    pen.setColor(QColor(255,0,0));
    //设置线条的粗细
    pen.setWidth(5);
    //设置样式
    pen.setStyle(Qt::DashLine);

    //让painter对象应用pen对象
    painter.setPen(pen);


    QBrush brush;
    brush.setColor(QColor(0,255,0));
//    brush.setStyle(Qt::SolidPattern);
     brush.setStyle(Qt::Dense1Pattern);
    painter.setBrush(brush);

//      QFont font("微软雅黑",24);
//      painter.setFont(font);

    //画一个线段
//    painter.drawLine(20,20,200,20);
//    painter.drawLine(QPoint(20,100),QPoint(200,100));

//    painter.drawLine(50,10,30,60);


    //或一个矩形
//    painter.drawRect(100,100,300,200);

    //画圆
    painter.drawEllipse(200,200,100,90);

//    painter.drawText(100,100,"hello");
}

